package com.example.demo.web;

import com.example.demo.dao.*;
import com.example.demo.entity.Book;
import com.example.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("web1")
@Controller
public class book1Control {
    @Autowired
    UserMapper userMapper;
    @Autowired
    BookUserMapper bookUserMapper;
    @Autowired
    BookMapper bookMapper;




    @RequestMapping("delete/{id}")
    public String delete(@PathVariable("id") String xxx){
        userMapper.delete(xxx);
        return "redirect:/web/listhtml";
    }

    @RequestMapping("add")
    public String add(User user){
        return "/user/add";
    }

    @PostMapping("save")
    public String save(User user){
        userMapper.save(user);
        return "redirect:/web/listhtml";
    }

    @GetMapping("edit/{id}")
    public String edit(@PathVariable("id") String id,ModelMap map){
        User user=userMapper.cel(id);
        map.put("user1",user);
        return "/user/edit";
    }

    @RequestMapping("update")
    public String update(User user){
        userMapper.update(user);
        return "redirect:/web/listhtml";
    }
}